3 use Wikimedia\Rdbms\IDatabase
;
4 use MediaWiki\Linker\LinkTarget
;
5 use Wikimedia\Assert\Assert
;
6 use Wikimedia\Rdbms\LoadBalancer
;
9 * Class performing complex database queries related to WatchedItems.
16 * @license GPL-2.0-or-later
18 class WatchedItemQueryService
{
20 const DIR_OLDER
= 'older';
21 const DIR_NEWER
= 'newer';
23 const INCLUDE_FLAGS
= 'flags';
24 const INCLUDE_USER
= 'user';
25 const INCLUDE_USER_ID
= 'userid';
26 const INCLUDE_COMMENT
= 'comment';
27 const INCLUDE_PATROL_INFO
= 'patrol';
28 const INCLUDE_AUTOPATROL_INFO
= 'autopatrol';
29 const INCLUDE_SIZES
= 'sizes';
30 const INCLUDE_LOG_INFO
= 'loginfo';
31 const INCLUDE_TAGS
= 'tags';
33 // FILTER_* constants are part of public API (are used in ApiQueryWatchlist and
34 // ApiQueryWatchlistRaw classes) and should not be changed.
35 // Changing values of those constants will result in a breaking change in the API
36 const FILTER_MINOR
= 'minor';
37 const FILTER_NOT_MINOR
= '!minor';
38 const FILTER_BOT
= 'bot';
39 const FILTER_NOT_BOT
= '!bot';
40 const FILTER_ANON
= 'anon';
41 const FILTER_NOT_ANON
= '!anon';
42 const FILTER_PATROLLED
= 'patrolled';
43 const FILTER_NOT_PATROLLED
= '!patrolled';
44 const FILTER_AUTOPATROLLED
= 'autopatrolled';
45 const FILTER_NOT_AUTOPATROLLED
= '!autopatrolled';
46 const FILTER_UNREAD
= 'unread';
47 const FILTER_NOT_UNREAD
= '!unread';
48 const FILTER_CHANGED
= 'changed';
49 const FILTER_NOT_CHANGED
= '!changed';
51 const SORT_ASC
= 'ASC';
52 const SORT_DESC
= 'DESC';
57 private $loadBalancer;
59 /** @var WatchedItemQueryServiceExtension[]|null */
60 private $extensions = null;
62 /** @var CommentStore */
63 private $commentStore;
65 /** @var ActorMigration */
66 private $actorMigration;
68 /** @var WatchedItemStoreInterface */
69 private $watchedItemStore;
71 public function __construct(
72 LoadBalancer
$loadBalancer,
73 CommentStore
$commentStore,
74 ActorMigration
$actorMigration,
75 WatchedItemStoreInterface
$watchedItemStore
77 $this->loadBalancer
= $loadBalancer;
78 $this->commentStore
= $commentStore;
79 $this->actorMigration
= $actorMigration;
80 $this->watchedItemStore
= $watchedItemStore;
84 * @return WatchedItemQueryServiceExtension[]
86 private function getExtensions() {
87 if ( $this->extensions
=== null ) {
88 $this->extensions
= [];
89 Hooks
::run( 'WatchedItemQueryServiceExtensions', [ &$this->extensions
, $this ] );
91 return $this->extensions
;
97 private function getConnection() {
98 return $this->loadBalancer
->getConnectionRef( DB_REPLICA
, [ 'watchlist' ] );
103 * @param array $options Allowed keys:
104 * 'includeFields' => string[] RecentChange fields to be included in the result,
105 * self::INCLUDE_* constants should be used
106 * 'filters' => string[] optional filters to narrow down resulted items
107 * 'namespaceIds' => int[] optional namespace IDs to filter by
108 * (defaults to all namespaces)
109 * 'allRevisions' => bool return multiple revisions of the same page if true,
110 * only the most recent if false (default)
111 * 'rcTypes' => int[] which types of RecentChanges to include
112 * (defaults to all types), allowed values: RC_EDIT, RC_NEW,
113 * RC_LOG, RC_EXTERNAL, RC_CATEGORIZE
114 * 'onlyByUser' => string only list changes by a specified user
115 * 'notByUser' => string do not incluide changes by a specified user
116 * 'dir' => string in which direction to enumerate, accepted values:
117 * - DIR_OLDER list newest first
118 * - DIR_NEWER list oldest first
119 * 'start' => string (format accepted by wfTimestamp) requires 'dir' option,
120 * timestamp to start enumerating from
121 * 'end' => string (format accepted by wfTimestamp) requires 'dir' option,
122 * timestamp to end enumerating
123 * 'watchlistOwner' => User user whose watchlist items should be listed if different
124 * than the one specified with $user param,
125 * requires 'watchlistOwnerToken' option
126 * 'watchlistOwnerToken' => string a watchlist token used to access another user's
127 * watchlist, used with 'watchlistOwnerToken' option
128 * 'limit' => int maximum numbers of items to return
129 * 'usedInGenerator' => bool include only RecentChange id field required by the
130 * generator ('rc_cur_id' or 'rc_this_oldid') if true, or all
131 * id fields ('rc_cur_id', 'rc_this_oldid', 'rc_last_oldid')
133 * @param array|null &$startFrom Continuation value: [ string $rcTimestamp, int $rcId ]
134 * @return array of pairs ( WatchedItem $watchedItem, string[] $recentChangeInfo ),
135 * where $recentChangeInfo contains the following keys:
142 * Additional keys could be added by specifying the 'includeFields' option
144 public function getWatchedItemsWithRecentChangeInfo(
145 User
$user, array $options = [], &$startFrom = null
148 'includeFields' => [],
149 'namespaceIds' => [],
151 'allRevisions' => false,
152 'usedInGenerator' => false
156 !isset( $options['rcTypes'] )
157 ||
!array_diff( $options['rcTypes'], [ RC_EDIT
, RC_NEW
, RC_LOG
, RC_EXTERNAL
, RC_CATEGORIZE
] ),
158 '$options[\'rcTypes\']',
159 'must be an array containing only: RC_EDIT, RC_NEW, RC_LOG, RC_EXTERNAL and/or RC_CATEGORIZE'
162 !isset( $options['dir'] ) ||
in_array( $options['dir'], [ self
::DIR_OLDER
, self
::DIR_NEWER
] ),
164 'must be DIR_OLDER or DIR_NEWER'
167 !isset( $options['start'] ) && !isset( $options['end'] ) && $startFrom === null
168 ||
isset( $options['dir'] ),
170 'must be provided when providing the "start" or "end" options or the $startFrom parameter'
173 !isset( $options['startFrom'] ),
174 '$options[\'startFrom\']',
175 'must not be provided, use $startFrom instead'
178 !isset( $startFrom ) ||
( is_array( $startFrom ) && count( $startFrom ) === 2 ),
180 'must be a two-element array'
182 if ( array_key_exists( 'watchlistOwner', $options ) ) {
183 Assert
::parameterType(
185 $options['watchlistOwner'],
186 '$options[\'watchlistOwner\']'
189 isset( $options['watchlistOwnerToken'] ),
190 '$options[\'watchlistOwnerToken\']',
191 'must be provided when providing watchlistOwner option'
195 $db = $this->getConnection();
197 $tables = $this->getWatchedItemsWithRCInfoQueryTables( $options );
198 $fields = $this->getWatchedItemsWithRCInfoQueryFields( $options );
199 $conds = $this->getWatchedItemsWithRCInfoQueryConds( $db, $user, $options );
200 $dbOptions = $this->getWatchedItemsWithRCInfoQueryDbOptions( $options );
201 $joinConds = $this->getWatchedItemsWithRCInfoQueryJoinConds( $options );
203 if ( $startFrom !== null ) {
204 $conds[] = $this->getStartFromConds( $db, $options, $startFrom );
207 foreach ( $this->getExtensions() as $extension ) {
208 $extension->modifyWatchedItemsWithRCInfoQuery(
209 $user, $options, $db,
227 $limit = $dbOptions['LIMIT'] ?? INF
;
230 foreach ( $res as $row ) {
231 if ( --$limit <= 0 ) {
232 $startFrom = [ $row->rc_timestamp
, $row->rc_id
];
236 $target = new TitleValue( (int)$row->rc_namespace
, $row->rc_title
);
241 $this->watchedItemStore
->getLatestNotificationTimestamp(
242 $row->wl_notificationtimestamp
, $user, $target
245 $this->getRecentChangeFieldsFromRow( $row )
249 foreach ( $this->getExtensions() as $extension ) {
250 $extension->modifyWatchedItemsWithRCInfo( $user, $options, $db, $items, $res, $startFrom );
257 * For simple listing of user's watchlist items, see WatchedItemStore::getWatchedItemsForUser
260 * @param array $options Allowed keys:
261 * 'sort' => string optional sorting by namespace ID and title
262 * one of the self::SORT_* constants
263 * 'namespaceIds' => int[] optional namespace IDs to filter by (defaults to all namespaces)
264 * 'limit' => int maximum number of items to return
265 * 'filter' => string optional filter, one of the self::FILTER_* contants
266 * 'from' => LinkTarget requires 'sort' key, only return items starting from
267 * those related to the link target
268 * 'until' => LinkTarget requires 'sort' key, only return items until
269 * those related to the link target
270 * 'startFrom' => LinkTarget requires 'sort' key, only return items starting from
271 * those related to the link target, allows to skip some link targets
272 * specified using the form option
273 * @return WatchedItem[]
275 public function getWatchedItemsForUser( User
$user, array $options = [] ) {
276 if ( $user->isAnon() ) {
277 // TODO: should this just return an empty array or rather complain loud at this point
278 // as e.g. ApiBase::getWatchlistUser does?
282 $options +
= [ 'namespaceIds' => [] ];
285 !isset( $options['sort'] ) ||
in_array( $options['sort'], [ self
::SORT_ASC
, self
::SORT_DESC
] ),
286 '$options[\'sort\']',
287 'must be SORT_ASC or SORT_DESC'
290 !isset( $options['filter'] ) ||
in_array(
291 $options['filter'], [ self
::FILTER_CHANGED
, self
::FILTER_NOT_CHANGED
]
293 '$options[\'filter\']',
294 'must be FILTER_CHANGED or FILTER_NOT_CHANGED'
297 !isset( $options['from'] ) && !isset( $options['until'] ) && !isset( $options['startFrom'] )
298 ||
isset( $options['sort'] ),
299 '$options[\'sort\']',
300 'must be provided if any of "from", "until", "startFrom" options is provided'
303 $db = $this->getConnection();
305 $conds = $this->getWatchedItemsForUserQueryConds( $db, $user, $options );
306 $dbOptions = $this->getWatchedItemsForUserQueryDbOptions( $options );
310 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
317 foreach ( $res as $row ) {
318 $target = new TitleValue( (int)$row->wl_namespace
, $row->wl_title
);
319 // todo these could all be cached at some point?
320 $watchedItems[] = new WatchedItem(
323 $this->watchedItemStore
->getLatestNotificationTimestamp(
324 $row->wl_notificationtimestamp
, $user, $target
329 return $watchedItems;
332 private function getRecentChangeFieldsFromRow( stdClass
$row ) {
333 // FIXME: This can be simplified to single array_filter call filtering by key value,
334 // now we have stopped supporting PHP 5.5
335 $allFields = get_object_vars( $row );
336 $rcKeys = array_filter(
337 array_keys( $allFields ),
339 return substr( $key, 0, 3 ) === 'rc_';
342 return array_intersect_key( $allFields, array_flip( $rcKeys ) );
345 private function getWatchedItemsWithRCInfoQueryTables( array $options ) {
346 $tables = [ 'recentchanges', 'watchlist' ];
347 if ( !$options['allRevisions'] ) {
350 if ( in_array( self
::INCLUDE_COMMENT
, $options['includeFields'] ) ) {
351 $tables +
= $this->commentStore
->getJoin( 'rc_comment' )['tables'];
353 if ( in_array( self
::INCLUDE_USER
, $options['includeFields'] ) ||
354 in_array( self
::INCLUDE_USER_ID
, $options['includeFields'] ) ||
355 in_array( self
::FILTER_ANON
, $options['filters'] ) ||
356 in_array( self
::FILTER_NOT_ANON
, $options['filters'] ) ||
357 array_key_exists( 'onlyByUser', $options ) ||
array_key_exists( 'notByUser', $options )
359 $tables +
= $this->actorMigration
->getJoin( 'rc_user' )['tables'];
364 private function getWatchedItemsWithRCInfoQueryFields( array $options ) {
372 'wl_notificationtimestamp'
380 if ( $options['usedInGenerator'] ) {
381 if ( $options['allRevisions'] ) {
382 $rcIdFields = [ 'rc_this_oldid' ];
384 $rcIdFields = [ 'rc_cur_id' ];
387 $fields = array_merge( $fields, $rcIdFields );
389 if ( in_array( self
::INCLUDE_FLAGS
, $options['includeFields'] ) ) {
390 $fields = array_merge( $fields, [ 'rc_type', 'rc_minor', 'rc_bot' ] );
392 if ( in_array( self
::INCLUDE_USER
, $options['includeFields'] ) ) {
393 $fields['rc_user_text'] = $this->actorMigration
->getJoin( 'rc_user' )['fields']['rc_user_text'];
395 if ( in_array( self
::INCLUDE_USER_ID
, $options['includeFields'] ) ) {
396 $fields['rc_user'] = $this->actorMigration
->getJoin( 'rc_user' )['fields']['rc_user'];
398 if ( in_array( self
::INCLUDE_COMMENT
, $options['includeFields'] ) ) {
399 $fields +
= $this->commentStore
->getJoin( 'rc_comment' )['fields'];
401 if ( in_array( self
::INCLUDE_PATROL_INFO
, $options['includeFields'] ) ) {
402 $fields = array_merge( $fields, [ 'rc_patrolled', 'rc_log_type' ] );
404 if ( in_array( self
::INCLUDE_SIZES
, $options['includeFields'] ) ) {
405 $fields = array_merge( $fields, [ 'rc_old_len', 'rc_new_len' ] );
407 if ( in_array( self
::INCLUDE_LOG_INFO
, $options['includeFields'] ) ) {
408 $fields = array_merge( $fields, [ 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ] );
410 if ( in_array( self
::INCLUDE_TAGS
, $options['includeFields'] ) ) {
411 // prefixed with rc_ to include the field in getRecentChangeFieldsFromRow
412 $fields['rc_tags'] = ChangeTags
::makeTagSummarySubquery( 'recentchanges' );
418 private function getWatchedItemsWithRCInfoQueryConds(
423 $watchlistOwnerId = $this->getWatchlistOwnerId( $user, $options );
424 $conds = [ 'wl_user' => $watchlistOwnerId ];
426 if ( !$options['allRevisions'] ) {
427 $conds[] = $db->makeList(
428 [ 'rc_this_oldid=page_latest', 'rc_type=' . RC_LOG
],
433 if ( $options['namespaceIds'] ) {
434 $conds['wl_namespace'] = array_map( 'intval', $options['namespaceIds'] );
437 if ( array_key_exists( 'rcTypes', $options ) ) {
438 $conds['rc_type'] = array_map( 'intval', $options['rcTypes'] );
441 $conds = array_merge(
443 $this->getWatchedItemsWithRCInfoQueryFilterConds( $user, $options )
446 $conds = array_merge( $conds, $this->getStartEndConds( $db, $options ) );
448 if ( !isset( $options['start'] ) && !isset( $options['end'] ) && $db->getType() === 'mysql' ) {
449 // This is an index optimization for mysql
450 $conds[] = 'rc_timestamp > ' . $db->addQuotes( '' );
453 $conds = array_merge( $conds, $this->getUserRelatedConds( $db, $user, $options ) );
455 $deletedPageLogCond = $this->getExtraDeletedPageLogEntryRelatedCond( $db, $user );
456 if ( $deletedPageLogCond ) {
457 $conds[] = $deletedPageLogCond;
463 private function getWatchlistOwnerId( User
$user, array $options ) {
464 if ( array_key_exists( 'watchlistOwner', $options ) ) {
465 /** @var User $watchlistOwner */
466 $watchlistOwner = $options['watchlistOwner'];
467 $ownersToken = $watchlistOwner->getOption( 'watchlisttoken' );
468 $token = $options['watchlistOwnerToken'];
469 if ( $ownersToken == '' ||
!hash_equals( $ownersToken, $token ) ) {
470 throw ApiUsageException
::newWithMessage( null, 'apierror-bad-watchlist-token', 'bad_wltoken' );
472 return $watchlistOwner->getId();
474 return $user->getId();
477 private function getWatchedItemsWithRCInfoQueryFilterConds( User
$user, array $options ) {
480 if ( in_array( self
::FILTER_MINOR
, $options['filters'] ) ) {
481 $conds[] = 'rc_minor != 0';
482 } elseif ( in_array( self
::FILTER_NOT_MINOR
, $options['filters'] ) ) {
483 $conds[] = 'rc_minor = 0';
486 if ( in_array( self
::FILTER_BOT
, $options['filters'] ) ) {
487 $conds[] = 'rc_bot != 0';
488 } elseif ( in_array( self
::FILTER_NOT_BOT
, $options['filters'] ) ) {
489 $conds[] = 'rc_bot = 0';
492 if ( in_array( self
::FILTER_ANON
, $options['filters'] ) ) {
493 $conds[] = $this->actorMigration
->isAnon(
494 $this->actorMigration
->getJoin( 'rc_user' )['fields']['rc_user']
496 } elseif ( in_array( self
::FILTER_NOT_ANON
, $options['filters'] ) ) {
497 $conds[] = $this->actorMigration
->isNotAnon(
498 $this->actorMigration
->getJoin( 'rc_user' )['fields']['rc_user']
502 if ( $user->useRCPatrol() ||
$user->useNPPatrol() ) {
503 // TODO: not sure if this should simply ignore patrolled filters if user does not have the patrol
504 // right, or maybe rather fail loud at this point, same as e.g. ApiQueryWatchlist does?
505 if ( in_array( self
::FILTER_PATROLLED
, $options['filters'] ) ) {
506 $conds[] = 'rc_patrolled != ' . RecentChange
::PRC_UNPATROLLED
;
507 } elseif ( in_array( self
::FILTER_NOT_PATROLLED
, $options['filters'] ) ) {
508 $conds['rc_patrolled'] = RecentChange
::PRC_UNPATROLLED
;
511 if ( in_array( self
::FILTER_AUTOPATROLLED
, $options['filters'] ) ) {
512 $conds['rc_patrolled'] = RecentChange
::PRC_AUTOPATROLLED
;
513 } elseif ( in_array( self
::FILTER_NOT_AUTOPATROLLED
, $options['filters'] ) ) {
514 $conds[] = 'rc_patrolled != ' . RecentChange
::PRC_AUTOPATROLLED
;
518 if ( in_array( self
::FILTER_UNREAD
, $options['filters'] ) ) {
519 $conds[] = 'rc_timestamp >= wl_notificationtimestamp';
520 } elseif ( in_array( self
::FILTER_NOT_UNREAD
, $options['filters'] ) ) {
521 // TODO: should this be changed to use Database::makeList?
522 $conds[] = 'wl_notificationtimestamp IS NULL OR rc_timestamp < wl_notificationtimestamp';
528 private function getStartEndConds( IDatabase
$db, array $options ) {
529 if ( !isset( $options['start'] ) && !isset( $options['end'] ) ) {
535 if ( isset( $options['start'] ) ) {
536 $after = $options['dir'] === self
::DIR_OLDER ?
'<=' : '>=';
537 $conds[] = 'rc_timestamp ' . $after . ' ' .
538 $db->addQuotes( $db->timestamp( $options['start'] ) );
540 if ( isset( $options['end'] ) ) {
541 $before = $options['dir'] === self
::DIR_OLDER ?
'>=' : '<=';
542 $conds[] = 'rc_timestamp ' . $before . ' ' .
543 $db->addQuotes( $db->timestamp( $options['end'] ) );
549 private function getUserRelatedConds( IDatabase
$db, User
$user, array $options ) {
550 if ( !array_key_exists( 'onlyByUser', $options ) && !array_key_exists( 'notByUser', $options ) ) {
556 if ( array_key_exists( 'onlyByUser', $options ) ) {
557 $byUser = User
::newFromName( $options['onlyByUser'], false );
558 $conds[] = $this->actorMigration
->getWhere( $db, 'rc_user', $byUser )['conds'];
559 } elseif ( array_key_exists( 'notByUser', $options ) ) {
560 $byUser = User
::newFromName( $options['notByUser'], false );
561 $conds[] = 'NOT(' . $this->actorMigration
->getWhere( $db, 'rc_user', $byUser )['conds'] . ')';
564 // Avoid brute force searches (T19342)
566 if ( !$user->isAllowed( 'deletedhistory' ) ) {
567 $bitmask = Revision
::DELETED_USER
;
568 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
569 $bitmask = Revision
::DELETED_USER | Revision
::DELETED_RESTRICTED
;
572 $conds[] = $db->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask";
578 private function getExtraDeletedPageLogEntryRelatedCond( IDatabase
$db, User
$user ) {
579 // LogPage::DELETED_ACTION hides the affected page, too. So hide those
580 // entirely from the watchlist, or someone could guess the title.
582 if ( !$user->isAllowed( 'deletedhistory' ) ) {
583 $bitmask = LogPage
::DELETED_ACTION
;
584 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
585 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
588 return $db->makeList( [
589 'rc_type != ' . RC_LOG
,
590 $db->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
596 private function getStartFromConds( IDatabase
$db, array $options, array $startFrom ) {
597 $op = $options['dir'] === self
::DIR_OLDER ?
'<' : '>';
598 list( $rcTimestamp, $rcId ) = $startFrom;
599 $rcTimestamp = $db->addQuotes( $db->timestamp( $rcTimestamp ) );
601 return $db->makeList(
603 "rc_timestamp $op $rcTimestamp",
606 "rc_timestamp = $rcTimestamp",
616 private function getWatchedItemsForUserQueryConds( IDatabase
$db, User
$user, array $options ) {
617 $conds = [ 'wl_user' => $user->getId() ];
618 if ( $options['namespaceIds'] ) {
619 $conds['wl_namespace'] = array_map( 'intval', $options['namespaceIds'] );
621 if ( isset( $options['filter'] ) ) {
622 $filter = $options['filter'];
623 if ( $filter === self
::FILTER_CHANGED
) {
624 $conds[] = 'wl_notificationtimestamp IS NOT NULL';
626 $conds[] = 'wl_notificationtimestamp IS NULL';
630 if ( isset( $options['from'] ) ) {
631 $op = $options['sort'] === self
::SORT_ASC ?
'>' : '<';
632 $conds[] = $this->getFromUntilTargetConds( $db, $options['from'], $op );
634 if ( isset( $options['until'] ) ) {
635 $op = $options['sort'] === self
::SORT_ASC ?
'<' : '>';
636 $conds[] = $this->getFromUntilTargetConds( $db, $options['until'], $op );
638 if ( isset( $options['startFrom'] ) ) {
639 $op = $options['sort'] === self
::SORT_ASC ?
'>' : '<';
640 $conds[] = $this->getFromUntilTargetConds( $db, $options['startFrom'], $op );
647 * Creates a query condition part for getting only items before or after the given link target
648 * (while ordering using $sort mode)
650 * @param IDatabase $db
651 * @param LinkTarget $target
652 * @param string $op comparison operator to use in the conditions
655 private function getFromUntilTargetConds( IDatabase
$db, LinkTarget
$target, $op ) {
656 return $db->makeList(
658 "wl_namespace $op " . $target->getNamespace(),
661 'wl_namespace = ' . $target->getNamespace(),
662 "wl_title $op= " . $db->addQuotes( $target->getDBkey() )
671 private function getWatchedItemsWithRCInfoQueryDbOptions( array $options ) {
674 if ( array_key_exists( 'dir', $options ) ) {
675 $sort = $options['dir'] === self
::DIR_OLDER ?
' DESC' : '';
676 $dbOptions['ORDER BY'] = [ 'rc_timestamp' . $sort, 'rc_id' . $sort ];
679 if ( array_key_exists( 'limit', $options ) ) {
680 $dbOptions['LIMIT'] = (int)$options['limit'] +
1;
686 private function getWatchedItemsForUserQueryDbOptions( array $options ) {
688 if ( array_key_exists( 'sort', $options ) ) {
689 $dbOptions['ORDER BY'] = [
690 "wl_namespace {$options['sort']}",
691 "wl_title {$options['sort']}"
693 if ( count( $options['namespaceIds'] ) === 1 ) {
694 $dbOptions['ORDER BY'] = "wl_title {$options['sort']}";
697 if ( array_key_exists( 'limit', $options ) ) {
698 $dbOptions['LIMIT'] = (int)$options['limit'];
703 private function getWatchedItemsWithRCInfoQueryJoinConds( array $options ) {
705 'watchlist' => [ 'JOIN',
707 'wl_namespace=rc_namespace',
712 if ( !$options['allRevisions'] ) {
713 $joinConds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
715 if ( in_array( self
::INCLUDE_COMMENT
, $options['includeFields'] ) ) {
716 $joinConds +
= $this->commentStore
->getJoin( 'rc_comment' )['joins'];
718 if ( in_array( self
::INCLUDE_USER
, $options['includeFields'] ) ||
719 in_array( self
::INCLUDE_USER_ID
, $options['includeFields'] ) ||
720 in_array( self
::FILTER_ANON
, $options['filters'] ) ||
721 in_array( self
::FILTER_NOT_ANON
, $options['filters'] ) ||
722 array_key_exists( 'onlyByUser', $options ) ||
array_key_exists( 'notByUser', $options )
724 $joinConds +
= $this->actorMigration
->getJoin( 'rc_user' )['joins'];